package com.xd.springboot.listener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpServletRequest;

@Component
public class MyServletRequestListener implements ServletRequestListener {
    private  static  final Logger log = LoggerFactory.getLogger(MyHttpSessionListener.class);

    @Override
    public void requestInitialized(ServletRequestEvent sre) {
        HttpServletRequest request = (HttpServletRequest)sre.getServletRequest();
        log.info("sesson id = {}",request.getRequestedSessionId());
        log.info("request url = {}",request.getRequestURL());
        request.setAttribute("name","test");
    }

    @Override
    public void requestDestroyed(ServletRequestEvent sre) {
        log.info("request end");
        HttpServletRequest request = (HttpServletRequest) sre.getServletRequest();
        log.info("request attribute the value of name ={}",request.getAttribute("name"));
    }


}
